﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

namespace StevensReceipts.Web
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "DefaultApiGet",
                routeTemplate: "api/{controller}"
            );
            config.Routes.MapHttpRoute(
                name: "DefaultApiWithParam",
                routeTemplate: "api/{controller}/{id}",
                defaults: null,
                constraints: new {id= @"^\d+$"}
            );
            config.Routes.MapHttpRoute(
                name: "CustomLookup",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );


            var json = config.Formatters.JsonFormatter;
            json.SerializerSettings.PreserveReferencesHandling =
                Newtonsoft.Json.PreserveReferencesHandling.Objects;

            config.Formatters.Remove(config.Formatters.XmlFormatter);

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi", 
            //    routeTemplate: "api/{area}/{controller}/{id}",
            //    defaults: new {id = RouteParameter.Optional});
        }
    }
}
